package com.clms.system.controller;

import com.clms.common.R;
import com.clms.system.mapper.UserMapper;
import com.clms.system.pojo.entitry.SysUser;
import com.clms.system.pojo.vo.UserVo;
import com.clms.system.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @program: clms-third
 * @description:
 * @author: 大鱼
 * @create: 2021-07-19 16:20
 **/
@RestController
@RequestMapping("/system/user")
//@CrossOrigin
@Api(value = "用户控制类")
public class UserController {
    @Autowired
    UserService userService;

    @ApiOperation("查询用户")
    @PostMapping("/initUerTable/{currentPage}/{pageSize}")
    public R usertable(@ApiParam("获取分页数") @PathVariable("currentPage") Integer currentPage, @ApiParam("封装前台搜索条件") @PathVariable("pageSize") Integer pageSize, @RequestBody UserVo userVo) {
        return userService.findAllUserPage(currentPage, pageSize, userVo);
    }

    @GetMapping("updataUserStatus/{userId}/{status}")
    public R updataUserStatus(@PathVariable("userId") Integer userId, @PathVariable("status") Integer status) {
        return userService.updataUserStatus(userId, status);
    }

    @DeleteMapping("deleteuserbyid/{roleId}")
    public R deleteUserById(@PathVariable("roleId") Integer roleId) {
        return userService.deleteUserById(roleId);
    }

    @PostMapping("addorupadte")
    public R userAddOrUpdate(@RequestBody SysUser userinfo) {
        return userService.userAddOrUpdate(userinfo);
    }

    @GetMapping("/getuserbyid/{userId}")
    public R getUserById(@PathVariable("userId") Integer userId) {
        return userService.getUserById(userId);
    }

    @PostMapping("onlyonecheck/byname")
    public R Checkbyname(@RequestBody Map map) {
        return userService.Checkbyname(map);
    }

    @GetMapping("resetbyid/{userid}")
    public R resetById(@PathVariable("userid") String userId) {
        return userService.resetById(userId);
    }
}
